<%
        if(session.getAttribute("admin") == null){
            response.sendRedirect("../PRINCIPAL/sesionExpirada.jsp");
        }
%>

<%@page import="java.util.Date"%>
<%@page import="java.util.Calendar"%>
<%@page language="Java" import="java.sql.*" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>ANALISIS Y DISEÑO 2</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="../CSS/default.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript" src="../JS/validar_formulario.js"></script>
<script type="text/javascript" src="../JS/funciones.js"></script>
</head>
<body onLoad=window.refresh>
<!-- start header -->
<jsp:useBean id="db" scope="request" class="conexion.DB" />
<div id="header">
<img src="../imagenes/usac1.jpg"/>        
	<h1><a href="#">FANTASY FOOTBALL</a></h1>
	<p><a href="#">USAC - AYD2</a></p>
        
       

</div>
<!-- end header -->
<!-- star menu -->
<div id="menu">
	<ul>
		<li class="current_page_item"><a href="inicio.jsp">INICIO</a></li>
		<li><a href="liga.jsp">LIGAS</a></li>
		<li><a href="equipo.jsp">EQUIPOS</a></li>                
                <li><a href="jugador.jsp">JUGADORES</a></li>
                <li><a href="cerrarSesion.jsp">CERRAR SESION</a> </li>
	</ul>
</div>
<!-- end menu -->
<!-- start page -->
<div id="page">
	<!-- start content -->
	<div id="content">
		<div class="post">
			<div class="title">
				<h2><a href="liga.jsp">MODIFICAR - LIGA</a></h2>
				<p><small>fase 2 </small></p>
			</div>
			<div class="entry">
                            <fieldset>
                               <p class="links">  <a class="comments"><label id="msg" for=""></label></a> </p>                           
                               <div>
                                   <span>Seleccione la Liga: </span>
                               </div>				
                               
                                <form method="POST">
                        <% 
                            if(db.connect()){
                                ResultSet rs=  null;
                                String opciones = "";                           
                                out.write("\n<select name=\"liga\" id=\"liga\" class=\"selects\">");
                                //out.write("<option value=-1>Elija un Pais</option>");
                                
                               try{
                                rs = db.seleccionar("*", "League", "1");

                                while(rs.next()){
                                   opciones += "\n<option value=\""+rs.getString(1) +"\">"+rs.getString(2) +"</option>";
                                }
                                }catch(Exception e){
                                    opciones += "error = " + e.toString();
                                }
                                out.write(opciones);
                                 /*out.write("<option value=2>" + db.seleccionar("*", "country", "1")+"</option>");*/
                                out.write("\n</select>");
                            }else{
                                out.write("\n<p><small><font color=red>Error al cargar los datos</font></small></p>");
                            }
                        %>
                        
                       
                            <input type="submit" value="Seleccionar" name="Seleccionar" />
                        </form>
                        <form method="POST" action="liga_modificar2.jsp" id="registro" name="registro">
                        <%
                            if(request.getParameter("liga") != null) {
                                //out.write("modificando la Liga <b>"+request.getParameter("liga")+"</b>");
                                
                                int idpais = 0;
                                    try {
                                        ResultSet rs = null;
                                         rs = db.seleccionar("*", "League", "id_league = " + request.getParameter("liga"));

                                while(rs.next()){
                                  idpais = rs.getInt("id_country_league");  
                                    out.write("\n<p></p>");
                                out.write("\n<p></p>");
                                out.write("\n<div>");
                                    out.write("\n<span>Nombre de la Liga:</span>");
                                out.write("\n</div>");
                                out.write("\n<div>");
                                    out.write("\n<td><input type=\"text\" name=\"nameliga\" id=\"nameliga\" size=\"30\" value=\""+rs.getString(2)+"\" /></td>");
                                    out.write("\n<td><input type=\"hidden\" name=\"nameliga2\" id=\"nameliga2\" size=\"30\" value=\""+rs.getString(2)+"\" /></td>");
                                out.write("\n</div>");
                                out.write("\n<p></p>");
                                out.write("\n<div>");
                                    out.write("\n<span>Tipo de Liga: </span>");
                                out.write("\n</div>");
				out.write("\n<div>");
                                
                                    if(rs.getString(1).equalsIgnoreCase(request.getParameter("liga"))) {
                                
                                    out.write("\n<input type=\"text\" name=\"tipoliga\" id=\"tipoliga\" size=\"30\" value=\""+rs.getString(3) +"\" />");
                                    out.write("\n</div>");
                                    out.write("\n<p></p>");
                                    out.write("\n<div>");
                                        out.write("\n<span>Cantidad de Equipos: </span></div>");
                                    out.write("\n<div>");
                                        out.write("\n<input type=\"text\" name=\"noequipos\" id=\"noequipos\" size=\"15\" value=\""+rs.getString(4) +"\" />");
                                    out.write("\n</div>");                                  
                                    out.write("\n<p></p>");
                                   out.write("\n<div>");
                                   }
                                                                       }
                                    } catch(Exception e) {
                                    
                                    }
                                    
                                   out.write("\n<span>Pais: </span>");
                               out.write("\n</div>");
                            
                         
                            if(db.connect()){
                                ResultSet rse=  null;
                                String opciones = "";                           
                                out.write("\n<select name=\"pais\" id=\"pais\" class=\"selects\">");
                                //out.write("<option value=-1>Elija un Pais</option>");
                                
                                try{
                                rse = db.seleccionar("*", "Country", "1");
                                //out.write("<BR>"+rse.getFetchSize()+"<BR>");
                                while(rse.next()){
                                   
                                    if(idpais == rse.getInt("id_country")){
                                        opciones += "\n<option value=\""+rse.getInt(1) +"\" selected>"+rse.getString(2) +"</option>";
                                   }else{
                                        opciones += "\n<option value=\""+rse.getInt(1) +"\">"+rse.getString(2) +"</option>";
                                    }
                                }
                                }catch(Exception e){
                                    opciones += "error = " + e.toString();
                                }
                                out.write(opciones);
                                 /*out.write("<option value=2>" + db.seleccionar("*", "country", "1")+"</option>");*/
                                 out.write("\n</select>");
                            }else{
                                out.write("\n<p><small><font color=red>Error al cargar los datos</font></small></p>");
                            }
                       
                                out.write("\n<p></p>");
                                out.write("\n<p></p>");
                                out.write("\n<center>");
                               // out.write("\n<form>");
                                out.write("\n<input type=\"button\" value=\"Modificar\" ID=\"Modificar\" name=\"Modificar\" onclick=\"aceptar_modificar()\"/>"); //onClick=\"location.href = \'liga_modificar2.jsp\' \">");
                                out.write("\n</form>");
                                
                                
                            }                       
                        %>                                               
                        </center>
			</fieldset>
                        
                        <%
                            /*if(request.getParameter("noequipos") != null) {
                                //out.write("Datos a modificar:<br>Nombre Liga: "+request.getParameter("nameliga")+"<br>Tipo Liga: "+request.getParameter("tipoliga")+"<br>maximo liga: "+request.getParameter("noequipos")+"<br>Id pais: "+request.getParameter("pais")+"<br>Liga anterior: "+request.getParameter("nameliga2"));
                                if(db.connect()){
                                    ResultSet res=null;
                                    res = db.seleccionar("*", "league", "name_league='"+request.getParameter("nameliga2")+"'");
                                     while(res.next()){
                                        //out.write(String.valueOf(res.getInt(1)));
                                        db.actualizar("name_league", request.getParameter("nameliga"), "League", "id_league="+res.getInt(1));
                                        db.actualizar("type_league", request.getParameter("tipoliga"), "League", "id_league="+res.getInt(1));
                                        db.actualizar("max_league", request.getParameter("noequipos"), "League", "id_league="+res.getInt(1));
                                        db.actualizar("id_country_league", request.getParameter("pais"), "League", "id_league="+res.getInt(1));
                                     }
                                }*/
                               // db.actualizar("name_league", request.getParameter("nameliga"), "League", condicion);
                            //}
                        %>
			</div>			
		</div>
		<div class="post">
			<div class="entry">
				<blockquote>
				</blockquote>
			</div>
			<p class="links">  <a href="#" class="comments">Inicio</a> </p>
                        <CENTER>
                         <H2></H2>
                         <% 
                         Date fecha = new Date();
                         out.print("<b>Hoy es:</b> ");
                         out.print(fecha.getDate());
                         out.print(" / ");
                         out.print(fecha.getMonth()+1);
                         out.print(" / ");
                         out.print(fecha.getYear()+1900);
                         %>
                         </CENTER> 
		</div>
	</div>
	<!-- end content -->
	<!-- start sidebar -->
	<div id="sidebar">
		<div id="search">
			<h2>Administrador</h2>
			
		</div>
		<ul>
			<li id="categories">
				<h2>MENU</h2>
				<ul>
					<li><a href="liga.jsp">LIGA</a>  </li>
                                        <ul>
                                            <li><a href="liga_crear.jsp">CREAR LIGA</a></li>
                                            <li><a href="liga_modificar.jsp">MODIFICAR LIGA</a></li>
                                            <li><a href="liga_eliminar.jsp">ELIMINAR LIGA</a></li>
                                        </ul>
                                            <p></p>
					<li><a href="equipo.jsp">EQUIPOS</a> </li>
                                        <li><a href="jugador.jsp">JUGADORES</a> </li>                                        
                                        <img src="../imagenes/pelota.png" alt="" />
				</ul>
			</li>
						
		</ul>
	</div>
	<!-- end sidebar -->
	<div id="extra" style="clear: both;">&nbsp;</div>
</div>
<!-- end page -->
<!-- start footer -->
<div id="footer">
	<p class="legal"> &copy;2012 Usac. All Rights Reserved.
		&nbsp;&nbsp;&bull;&nbsp;&nbsp;		
</div>
<!-- end footer -->
</body>
</html>
